package com.wuzheng.wisgo.sanitation.cloud.service.quartzjob.impl;

import com.wuzheng.wisgo.sanitation.cloud.model.mapbase.MapBaseCriteria;
import com.wuzheng.wisgo.sanitation.cloud.model.receviceinfonew.ReceviceInfoNewCriteria;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.gis.MapBase;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.locate.ReceiveInfoNew;
import com.wuzheng.wisgo.sanitation.cloud.service.gis.MapBaseService;
import com.wuzheng.wisgo.sanitation.cloud.service.locate.ReceiveInfoNewService;
import com.wuzheng.wisgo.sanitation.framework.util.BeanUtils;
import com.wuzheng.wisgo.sanitation.framework.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by sp on 2019/11/6 16:28.
 * <p>
 * Job 是 定时任务的具体执行逻辑
 * JobDetail 是 定时任务的定义
 */
@Slf4j
@DisallowConcurrentExecution
public class QuartzJobServiceImpl implements Job {


    @Autowired
    private ReceiveInfoNewService receiveInfoNewService;

    @Autowired
    private MapBaseService mapBaseService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //写你自己的逻辑
        log.info("Quartz execute , start run  ! ");
        List<String> list=new ArrayList<>();
        list.add("LS6HA1041JG782721");
        list.add("LS6HA1041JG7827212");
        list.add("LS8HA1041JG750962");
        list.add("LS8HA1041JG777874");
        list.add("LS8HA1041JG767738");
        list.stream().forEach(vin->{
            ReceviceInfoNewCriteria receviceInfoNewCriteria=new ReceviceInfoNewCriteria();
            receviceInfoNewCriteria.setRecVin(vin);
            List<ReceiveInfoNew> recVinList = receiveInfoNewService.selectList(receviceInfoNewCriteria);
            //vin码是唯一的码，所以理论上recVinList只能查出来一个
            if(recVinList.size()>0){
                if(StringUtils.isNotEmpty(recVinList.get(0).getId())){
                    receiveInfoNewService.deleteById(recVinList.get(0).getId());
                    ReceiveInfoNew recInsert=new ReceiveInfoNew();
                    ReceiveInfoNew receiveInfoNew = recVinList.get(0);
                    BeanUtils.copy(receiveInfoNew,recInsert);
                    recInsert.setId(UUID.randomUUID().toString());
                    Double s=Double.valueOf(recVinList.get(0).getRecLatitude()+0.001D);
                    Double s2=recVinList.get(0).getRecLongitude()+0.001D;
                    System.out.println("计算值："+s+"::::"+s2);
                    recInsert.setRecLatitude(s);
                    recInsert.setRecLongitude(s2);

                    recInsert.setModifier("sp");
                    recInsert.setModifyTime(new Date());
                    receiveInfoNewService.insert(recInsert);
                    MapBaseCriteria mapBaseCriteria=new MapBaseCriteria();
                    mapBaseCriteria.settLatitude(s);
                    mapBaseCriteria.settLongitude(s2);
                    List<MapBase> mapBaseList = mapBaseService.selectList(mapBaseCriteria);
                    if(mapBaseList.size()==0){
                       MapBase mapBase=new MapBase();
                       mapBase.setId(UUID.randomUUID().toString());
                       mapBase.settLongitude(s2);
                       mapBase.settLatitude(s);
                       mapBase.settTranLatitude(s);
                       mapBase.settTranLongitude(s2);
                       mapBase.settAddress("山东省日照市五莲区潮河镇五征集团");
                       mapBase.settMapType("1");
                       mapBase.setDeFlag(false);
                       mapBase.setCreateTime(new Date());
                       mapBase.setCreator("sp");
                       mapBase.setModifier("sp");
                       mapBase.setModifyTime(new Date());
                       mapBase.setIpAddress("127.0.0.1");
                       mapBaseService.insert(mapBase);
                    }
                }
            }
        });


    }
//    public static void main(String[] str){
//        Double s=120d;
//        Double s2=s+1;
//        System.out.println("计算值::::"+s2);
//    }
}
